<?php
/**
 * 模块对象
 * 
 * 用来描述模块的各种属性，如名称、版本等等
 *
 * @package if
 * @subpackage installer
 * @since 1.1.2
 */
class IModule extends IObject {
	private $name;
	private $summary;
	private $description;
	private $license;
	private $maintainers;
	private $release = array();//version, date
	private $deps = array();//source => destination
	private $changelog = array();//array( version => description )
	
	private $version;
	
	//安装相关的设置
	private $installable = false;
	private $id;
	
	/**
	 * 安装目录
	 *
	 * @var unknown_type
	 */
	private $dir;
	
	const STATUS_INSTALLED = 1;
	const STATUS_UNINSTALLED = 2;
	const STATUS_SKIPPED = 3;
	const STATUS_DISABLED = 4;
	
	function __construct($optionsOrConfigFile) {
		$options = array();
		if (is_array($optionsOrConfigFile)) {
			$options = $optionsOrConfigFile;
		}
		else {
			if (is_file($optionsOrConfigFile)) {//is file
				$options = require($optionsOrConfigFile);
			}
		}
		
		if (isset($options["name"])) {
			$this->name = $options["name"];
		}
		if (isset($options["summary"])) {
			$this->summary = $options["summary"];
		}
		if (isset($options["description"])) {
			$this->description = $options["description"];
		}
		if (isset($options["license"])) {
			$this->license = $options["license"];
		}
		if (isset($options["maintainers"])) {
			$this->maintainers = $options["maintainers"];
		}
		if (isset($options["release"])) {
			if (is_array($options["release"])
		  		&& isset($options["release"]["version"]) && isset($options["release"]["date"])) {
				$this->release = $options["release"];
				$this->version = $options["release"]["version"];
		  	}
		  	else {
				$this->_log("module '{$this->name}' defination 'release' error(not an array, or either version or dateis undefined)",  ILog::LOG_WARNING);
			}
		}
		
		if (isset($options["version"])) {
			$this->version = $options["version"];
		}

		if (isset($options["changelog"])) {
			if (is_array($options["changelog"])) {
				$this->changelog = $options["changelog"];
			}
			else {
				$this->_log("module '{$this->name}' defination 'changelog' error(not an array)",  ILog::LOG_WARNING);
			}
		}
		
		//安装相关的参数
		if (isset($options["installable"])) {
			$this->installable = $options["installable"];
		}
		if (isset($options["id"])) {
			$this->id = $options["id"];
		}
		else {
			$this->id = $this->name;
		}
	}
	
	function setName($name) {
		$this->name = $name;
	}
	
	function name() {
		return $this->name;
	}
	
	function summary() {
		return $this->summary;
	}
	
	function description() {
		return $this->description;
	}
	
	function license() {
		return $this->license;
	}
	
	function maintainers() {
		return $this->maintainers;
	}
	
	function release() {
		return $this->release;
	}
	
	function deps() {
		return $this->deps;
	}
	
	function changelog() {
		return $this->changelog;
	}
	
	function isInstallable() {
		return $this->installable;
	}
	
	function setInstallable($installable) {
		$this->installable = $installable;
	}
	
	function setDir($dir) {
		$this->dir = $dir;
	}
	
	function dir() {
		return $this->dir;
	}
	
	function id() {
		return $this->id;
	}
	
	function version() {
		return $this->version;
	}
	
	function isInstalled() {
		return version_compare(o("@registry.`{$this->id}`.version"), $this->version) == 0 &&
			o("@registry.`{$this->id}`.status") == self::STATUS_INSTALLED;
	}
}

?>